home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / util / cli / mcomms_1_4.lha / Src / touch.c < prev   
C/C++ Source or Header  |  1992-09-02  |  3KB  |  143 lines

  1. #define __USE_SYSBASE
  2.  
  3. #include <exec/types.h>
  4. #include <exec/execbase.h>
  5. #include <exec/memory.h>
  6. #include <dos/rdargs.h>
  7. #include <dos/dosasl.h>
  8. #include <dos/dosextens.h>
  9. #include <support/types.h>
  10. #include <support/exec.h>
  11.  
  12. #include <string.h>
  13.  
  14. #include <proto/exec.h>
  15. #include <proto/dos.h>
  16.  
  17. #include "touch.rev.h"
  18.  
  19. #define DOS_NAME        "dos.library"
  20. #define DOS_VERN         37L
  21.  
  22. #define TEMPLATE        "FILE/M,ONEDATE/S,ALL/S,QUIET/S"
  23.  
  24. STATIC CONST TEXT VersionString[]=
  25.     VERSION(PROG_NAME,PROG_VERSION,PROG_REVISION,PROG_DATE);
  26.  
  27. #define MSG_TOUCHED            "  Touched\n"
  28. #define MSG_NOT_TOUCHED    "  Not Touched"
  29.  
  30. #define OPT_FILE        0
  31. #define OPT_ONE            1
  32. #define OPT_ALL            2
  33. #define OPT_QUIET        3
  34. #define OPT_COUNT        4
  35.  
  36. #define NAME_SIZE        32
  37. #define PATH_SIZE        256
  38.  
  39. ULONG Touch(VOID)
  40. {
  41.     struct ExecBase *SysBase=*((struct ExecBase **)4);
  42.     struct DosLibrary *DOSBase;
  43.  
  44.     STATIC CONST STRPTR NoArgs[]={"#?",NULL};
  45.  
  46.     LONG Opts[OPT_COUNT];
  47.     ULONG TempRC,RC=RETURN_FAIL;
  48.     CHAR FName[NAME_SIZE],*CurArg,**ArgPtr;
  49.     BPTR CurrLock,OldLock;
  50.     struct RDArgs *Args;
  51.     struct AnchorPath *Anchor;
  52.     struct DateStamp ALIGNED StampData;
  53.     BOOL DoDir,ErrOccured=FALSE;
  54.  
  55.     unless(DOSBase=(struct DosLibrary *)OpenLibrary(DOS_NAME,DOS_VERN))
  56.     {
  57.         SetResult2(ERROR_INVALID_RESIDENT_LIBRARY);
  58.         goto InvalidDOS;
  59.     }
  60.  
  61.     unless(Anchor=AllocVec(sizeof(struct AnchorPath)+PATH_SIZE,MEMF_CLEAR))
  62.     {
  63.         PrintFault(IoErr(),NULL);                                /* Inform user */
  64.         goto NoMemory;
  65.     }
  66.  
  67.     clear(&Opts);                                                            /* Clear out args buffer */
  68.     unless(Args=ReadArgs(TEMPLATE,Opts,NULL))
  69.     {
  70.         PrintFault(IoErr(),NULL);                                /* Inform user */
  71.         goto NoArgs;
  72.     }
  73.  
  74.     DateStamp(&StampData);
  75.     ArgPtr=Opts[OPT_FILE] ? (STRPTR *)Opts[OPT_FILE] : (STRPTR *)NoArgs;
  76.     while(CurArg=*ArgPtr++)
  77.     {
  78.         clear(Anchor);
  79.         Anchor->ap_BreakBits=SIGBREAKF_CTRL_C;        /* Allow break */
  80.         Anchor->ap_Strlen=PATH_SIZE;                            /* We have a path buffer */
  81.         TempRC=MatchFirst(CurArg,Anchor);
  82.         while(TempRC==0)
  83.         {
  84.             strcpy(FName,Anchor->ap_Info.fib_FileName);
  85.             if(Anchor->ap_Info.fib_DirEntryType>=0)    /* This is dir */
  86.             {
  87.                 DoDir=TRUE;
  88.                 if(Opts[OPT_ALL])
  89.                 {
  90.                     unless(ftst(Anchor->ap_Flags,APF_DIDDIR))
  91.                     {
  92.                         fset(Anchor->ap_Flags,APF_DODIR);
  93.                         DoDir=FALSE;
  94.                     }
  95.                     fclr(Anchor->ap_Flags,APF_DIDDIR);
  96.                 }
  97.                 unless(DoDir)
  98.                     goto Next;
  99.             }
  100.             CurrLock=DupLock(Anchor->ap_Current->an_Lock);
  101.             OldLock=CurrentDir(CurrLock);
  102.             unless(Opts[OPT_ONE])
  103.                 DateStamp(&StampData);
  104.             if(SetFileDate(FName,&StampData))
  105.             {
  106.                 unless(Opts[OPT_QUIET])
  107.                 {
  108.                     PutStr(Anchor->ap_Buf);                /* Print path... */
  109.                     PutStr(MSG_TOUCHED);
  110.                 }
  111.             }
  112.             else
  113.             {
  114.                 PutStr(Anchor->ap_Buf);                /* Print path... */
  115.                 PrintFault(IoErr(),MSG_NOT_TOUCHED);
  116.                 ErrOccured=TRUE;
  117.             }
  118.             CurrentDir(OldLock);
  119.             UnLock(CurrLock);
  120. Next:
  121.             TempRC=MatchNext(Anchor);
  122.         }
  123.         if(TempRC==ERROR_NO_MORE_ENTRIES)
  124.             RC=(ErrOccured ? RETURN_ERROR : RETURN_OK);
  125.         else
  126.         {
  127.             PrintFault(TempRC,NULL);
  128.             RC=(TempRC==ERROR_BREAK ? RETURN_WARN : RETURN_FAIL);
  129.         }
  130.         MatchEnd(Anchor);
  131.         if(TempRC==ERROR_BREAK)
  132.             break;
  133.     }
  134.  
  135.     FreeArgs(Args);
  136. NoArgs:
  137.     FreeVec(Anchor);
  138. NoMemory:
  139.     CloseLibrary((struct Library *)DOSBase);
  140. InvalidDOS:
  141.     return(RC);
  142. }
  143.